package com.ddwl.funds.controller;


import com.ddwl.common.annotation.Auth;
import com.ddwl.common.annotation.Submit;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.funds.OrderRefundCreBo;
import com.ddwl.schema.bo.funds.PayOrderCreBo;
import com.ddwl.schema.vo.funds.OrderPaymentVo;
import com.ddwl.schema.vo.funds.OrderRefundsVo;
import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.schema.bo.funds.OrderPayBo;
import com.ddwl.funds.service.PaymentServer;
import com.ddwl.schema.vo.base.RestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 类PayController.java的实现描述：支付订单相关API
 *
 * @author zach
 * @Date :2020-09-24 15:46.
 */
@RestController
@Api(tags = "支付订单相关API",hidden = true)
public class OrderController extends BaseController {

    @Resource
    private PaymentServer paymentServer;

    @PostMapping("orderPayCre")
    @ApiOperation("创建预支付订单")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<OrderPaymentVo> create(@Valid @RequestBody PayOrderCreBo payOrderCreBo) {
        return RestVo.ok(BeanConverUtils.convertBean(paymentServer.createOrderPay(payOrderCreBo), OrderPaymentVo.class));
    }

    /**
     * 创建订单并且返回客户端需要的支付信息
     * @param orderPayBo
     * @return
     */
    @PostMapping("orderCreAndPay")
    @ApiOperation("创建订单并且返回客户端需要的支付信息")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<String> crePayment(@Valid @RequestBody OrderPayBo orderPayBo){
        return RestVo.ok(paymentServer.payment(orderPayBo));
    }


    @GetMapping("orderPayInfo")
    @ApiOperation("查询用户订单详情")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<OrderPaymentVo> orderPayInfo(@RequestParam String orderId) {
        return RestVo.ok(paymentServer.getOrderPay(orderId));
    }

    @Submit
    @PostMapping("refundsCre")
    @ApiOperation("创建预退款订单")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<OrderRefundsVo> refundsCre(@Valid @RequestBody OrderRefundCreBo creBo) {
        return RestVo.ok(paymentServer.createRefunds(creBo));
    }


    @GetMapping("refundsInfo")
    @ApiOperation("查询退款订单详情")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<OrderRefundsVo> refundsInfo(@RequestParam String bizRefundsNo) {
        return RestVo.ok(paymentServer.getRefunds(bizRefundsNo));
    }



}
